import { createSlice } from '@reduxjs/toolkit';
import type { PayloadAction } from '@reduxjs/toolkit';

interface AppState {
  loading: boolean;
  lang: 'zh' | 'en';
}

const initialState: AppState = {
  loading: false,
  lang: 'zh',
};

const appSlice = createSlice({
  name: 'app',
  initialState,
  reducers: {
    setLoading: (state, action: PayloadAction<boolean>) => {
      state.loading = action.payload;
    },
    setLang: (state, action: PayloadAction<'zh' | 'en'>) => {
      state.lang = action.payload;
    },
  },
});

export const { setLoading, setLang } = appSlice.actions;
export default appSlice.reducer;
